package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.*;
import tech.aistar.pojo.dao.CommentreplyRepository;
import tech.aistar.pojo.entity.Commentreply;
import tech.aistar.pojo.entity.Commentt;
import tech.aistar.service.UserService;
import tech.aistar.vo.Result;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("hui")
public class CommentreplyController {
    @Autowired
    private UserService userService;
    @Autowired
    private CommentreplyRepository commentreplyRepository;
    @GetMapping("ss/{id}")
    private Result sele(@PathVariable("id")String id){

        Commentreply commentreply= new Commentreply();
        commentreply.setFromId(Integer.valueOf(id));

        List<Commentreply> stuOp1 = commentreplyRepository.findAll(Example.of(commentreply));
                return new Result("200","查询成功",stuOp1);

    }
    @GetMapping ("inst/{ohcomment}/{oHfName}/{name}/{commenid}/{uid}")
    private Result ins(@PathVariable("ohcomment") String oHfVal,@PathVariable("oHfName") String oHfName,@PathVariable("name") String name,@PathVariable("commenid") Integer id,@PathVariable("uid") Integer uid)
    {
        Date tt = new Date();
        Commentreply commentreply1=new Commentreply();
        commentreply1.setContent(oHfVal);

        commentreply1.setCreateTime(String.valueOf(tt));
        commentreply1.setFromId(id);
        commentreply1.setFromName(name);
        commentreply1.setReplyId(uid);
        commentreply1.setReplyName(oHfName);
        commentreplyRepository.insert(commentreply1);
        return new Result("200","插入成功");
    }
    @PostMapping("del/{id}")
    private Result delt(@PathVariable("id") String id)
    {
        commentreplyRepository.deleteById(id);
        return new Result("200","删除成功");
    }
    @PostMapping("up/{zNum}/{uid}")
    private Result upde(@PathVariable("zNum") Integer number,@PathVariable("uid") String id)
    {
        Optional<Commentreply> op = commentreplyRepository.findById(id);
        Commentreply commentreply = op.get();
        commentreply.setNumber(number);
        commentreplyRepository.save(commentreply);
        return new Result("200","更新成功");
    }

}
